package org.wuqi.microweb.api.result;

import static org.wuqi.microweb.api.result.ResultEnum.FAIL;
import static org.wuqi.microweb.api.result.ResultEnum.SUCCESS;

/**
 * @author jjj
 * @program: earnest-money
 * @description:TODO
 * @date 2024-01-05 14:41:50
 */
public class Result<T> {
    private int code;
    private String message;
    private T data;

    public Result() {
    }

    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(int code, T data) {
        this.code = code;
        this.data = data;
    }

    public Result(String message, T data) {
        this.message = message;
        this.data = data;
    }
//    定时通用的方法
public static <T> Result<T> success(){
    return  success(SUCCESS);
}
    public static <T> Result<T> success(T data){
        return success(SUCCESS,data);
    }
    public static <T> Result<T> success(ResultEnum re){
        return success(re,null);
    }
    public static <T> Result<T> success(ResultEnum re,T data){
        Integer code = re.getCode();
        String msg = re.getMsg();
        return success(code,msg,data);
    }
    public static <T> Result<T> success(Integer code, String msg, T data){
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(msg);
        result.setData(data);
        return result;
    }



    public static <T> Result<T> fail(){
        return  success(FAIL);
    }
    public static <T> Result<T> fail(T data){
        return success(FAIL,data);
    }
    public static <T> Result<T> fail(ResultEnum re){
        return success(re,null);
    }
    public static <T> Result<T> fail(ResultEnum re,T data){
        Integer code = re.getCode();
        String msg = re.getMsg();
        return success(code,msg,data);
    }
    public static <T> Result<T> fail(Integer code, String msg, T data){
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(msg);
        result.setData(data);
        return result;
    }





    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}